using System;
using Microsoft.Xna.Framework;

namespace GameEngine.Units
{
	public class Particle : Animated
	{
		private ParticleType type;

		private TimeSpan? expirationTime;

		// TODO: add option to make the particle follow a unit, fly from one unit to other, dance araound or whatever... will be useful later... for example a unit that is shooting may produce a particle that moves from one unit to the other... although we probably will have to create projectile class
		public Particle(ParticleType type, World world, TimeSpan creationTime)
			: base(type, world)
		{
			this.type = type;
			this.expirationTime = TimeSpan.FromTicks(creationTime.Ticks + this.type.LifeTime.Ticks);
		}

		internal override void Update(GameTime gameTime)
		{
			if (!this.HasExpired && this.expirationTime.HasValue)
			{
				this.HasExpired = this.expirationTime.Value.CompareTo(gameTime.TotalGameTime) <= 0;
			}
		}

		public bool HasExpired { get; private set; }
	}
}
